<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition template="/templates/templateListar.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions">

	<ui:define name="conteudo">
		<ui:param name="actionBean" value="#{usuarioMB}" />

		<h:form id="frmUsuario">

			<p:hotkey bind="esc"
				handler="document.getElementById('frmTab:btnCancelar').click()" />


		</h:form>

		<h:form id="frmTab">
			<p:commandButton id="btnCancelar" action="#{usuarioMB.sair}"
				style="display:none" value="cancelar" />
			<p:commandButton actionListener="#{usuarioMB.abrirModal}"
				style="float:left" icon="ui-icon-disk" title="Incluir"
				update=":dialogCadastro" value="Novo Registro" ajax="true"
				oncomplete="dialogCadastroUsuario.show()">
				<f:param name="modooperacao" value="INCLUIR" />
			</p:commandButton>
			<p:dataTable id="tabela" var="item" value="#{usuarioMB.lista}"
				paginator="true" rows="10" emptyMessage="Não há registros"
				paginatorPosition="bottom"
				paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
				currentPageReportTemplate="(Página: {currentPage}/{totalPages})"
				rowsPerPageTemplate="10,15,25,50,100" selectionMode="single"
				rowKey="#{item.codigo}">
				<f:facet name="header">Cadastro de Usuários
				</f:facet>
				<p:column headerText="Código" sortBy="#{item.codigo}">
					<h:outputText value="#{item.codigo}" />
				</p:column>
				<p:column headerText="Nome" sortBy="#{item.nome}">

					<h:outputText value="#{item.nome}" />

				</p:column>
				<p:column headerText="Login" sortBy="#{item.login}">

					<h:outputText value="#{item.login}" />

				</p:column>
				<p:column headerText="E-mail" sortBy="#{item.email}">

					<h:outputText value="#{item.email}">
					</h:outputText>
				</p:column>

				<p:column headerText="Ações" style="text-align:center">

					<p:commandButton title="Alterar" icon="ui-icon-pencil"
						styleClass="styleBotao" actionListener="#{usuarioMB.abrirModal}"
						update=":dialogCadastro" ajax="true"
						oncomplete="dialogCadastroUsuario.show()">
						<f:setPropertyActionListener value="#{item.clone()}"
							target="#{usuarioMB.usuarioSelecionado}" />
						<f:param name="modooperacao" value="ALTERAR" />
					</p:commandButton>

					<p:commandButton actionListener="#{usuarioMB.abrirModal}"
						styleClass="styleBotao" icon="ui-icon-search" title="Consultar"
						update=":dialogCadastro" ajax="true"
						oncomplete="dialogCadastroUsuario.show()">
						<f:setPropertyActionListener value="#{item.clone()}"
							target="#{usuarioMB.usuarioSelecionado}" />
						<f:param name="modooperacao" value="CONSULTAR" />
					</p:commandButton>

					<p:commandButton title="Excluir" update=":Excluir"
						icon="ui-icon-close" oncomplete="confirmation.show()"
						styleClass="styleRed">

						<f:setPropertyActionListener
							target="#{usuarioMB.usuarioSelecionado}" value="#{item.clone()}" />
					</p:commandButton>

				</p:column>

				<f:facet name="footer">
					<p:outputLabel value="Total de " />
					<p:outputLabel value="#{fn:length(usuarioMB.lista)} registro(s)" />

				</f:facet>
			</p:dataTable>


		</h:form>

		<ui:include src="dialogCadastroUsuario.xhtml" />
		<ui:include src="/includes/confirmacaoExcluir.xhtml" />


	</ui:define>

</ui:composition>
